package com.fishery.refrigeratory.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fishery.entity.Result;
import com.fishery.refrigeratory.entity.Refrigeratory;
import com.fishery.refrigeratory.entity.RefrigeratoryAccessInfo;
import com.fishery.refrigeratory.service.RefrigeratoryAccessInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author wgz
 * @since 2021/1/20
 */


@Api(description = "冷库出入库信息接口")
@RestController
@CrossOrigin
@RequestMapping("/refrigeratory/refrigeratoryAccessInfo")
public class RefrigeratoryAccessInfoController {

    @Autowired
    private RefrigeratoryAccessInfoService refrigeratoryAccessInfoService;

    /**
     * 增加出入库信息
     * @author wgz
     * @since 2021/1/23
     * @param refrigeratoryAccessInfo
     */
    @PostMapping("/in")
    @ApiOperation("增加出入库信息")
    public Result createRefrigeratoryAccessInfo(@RequestBody @ApiParam(value = "出入库信息对象") RefrigeratoryAccessInfo refrigeratoryAccessInfo){
        return refrigeratoryAccessInfoService.createRefrigeratoryAccessInfo(refrigeratoryAccessInfo) == 1? Result.success(): Result.error();
    }

    /**
     * 修改出入库信息
     * @param refrigeratoryAccessInfo
     * @return
     */
    @PutMapping("/in")
    @ApiOperation("修改出入库信息")
    public Result updateRefrigeratoryAccessInfo (@RequestBody @ApiParam(value = "修改出入库信息对象") RefrigeratoryAccessInfo refrigeratoryAccessInfo) {
        return refrigeratoryAccessInfoService.updateRefrigeratoryAccessInfo(refrigeratoryAccessInfo) == 1? Result.success(): Result.error();
    }

    /**
     * 删除出入库信息
     * @param id
     * @return
     */
    @DeleteMapping("/in/{id}")
    @ApiOperation("删除出入库信息")
    public Result deleteRefrigeratoryAccessInfo(@PathVariable(value = "id") @ApiParam(value = "删除出入库信息id") String id) {
        return refrigeratoryAccessInfoService.deleteRefrigeratoryAccessInfo(id) == 1? Result.success(): Result.error();
    }


    /**
     * 根据出入库信息id查询出入库信息
     * @param id
     * @return
     */
    @GetMapping("/get/RefrigeratoryAccessInfo/{id}")
    @ApiOperation("根据出入库信息id查询出入库信息")
    public Result getRefrigeratoryAccessInfoById(@PathVariable(value = "id") @ApiParam(value = "出入库信息id") String id) {
        List<RefrigeratoryAccessInfo> refrigeratoryAccessInfoList = refrigeratoryAccessInfoService.getRefrigeratoryAccessInfoById(id);
        return refrigeratoryAccessInfoList.size() > 0 ? Result.success("查询成功").data(refrigeratoryAccessInfoList): Result.error("查询失败");
    }


    /**
     * 获得所有的出入库信息
     * @return
     */
    @GetMapping("/get/AllRefrigeratoryAccessInfo")
    @ApiOperation("获得所有的出入库信息")
    public Result getAllRefrigeratoryAccessInfo() {
        return Result.success().data(refrigeratoryAccessInfoService.getAllRefrigeratoryAccessInfo());
    }

    /**
     * 分页获取所有的出入库信息
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/get/AllRefrigeratoryAccessInfo/{page}/{size}")
    @ApiOperation("分页获取所有的出入库信息")
    public Result getAllPageRefrigeratoryAccessInfo(@PathVariable(value = "page") @ApiParam(value = "页数") Integer page,
                                                @PathVariable(value = "size") @ApiParam(value = "行数") Integer size) {
        return Result.success().data(refrigeratoryAccessInfoService.getAllRefrigeratoryAccessInfoByrefrigeratoryId(page,size));
    }


    /**
     * 根据冷库id查询出入库信息
     * @param refrigeratory_id
     * @return
     */
    @GetMapping("/get/RefrigeratoryAccessInfoByrefrigeratoryId/{id}")
    @ApiOperation("根据冷库id查询出入库信息")
    public Result getRefrigeratoryAccessInfoByrefrigeratoryId(@PathVariable(value = "id") @ApiParam(value = "冷库id") String refrigeratory_id) {
       return Result.success().data(refrigeratoryAccessInfoService.getRefrigeratoryAccessInfo(refrigeratory_id));
    }

    /**
     * 根据冷库id分页查询出入库信息
     * @param refrigeratory_id
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/get/RefrigeratoryAccessInfoByrefrigeratoryId/{id}/{page}/{size}")
    @ApiOperation("根据冷库id分页查询出入库信息")
    public Result getPageRefrigeratoryAccessInfoByrefrigeratoryId(@PathVariable(value = "id") @ApiParam(value = "冷库id") String refrigeratory_id,
                                                                  @PathVariable(value = "page") @ApiParam(value = "页数") Integer page,
                                                                  @PathVariable(value = "size") @ApiParam(value = "行数") Integer size) {
        return Result.success().data(refrigeratoryAccessInfoService.getPageRefrigeratoryAccessInfoByrefrigeratoryId(refrigeratory_id,page,size));
    }


}
